package array

import "fmt"

// 动态规划（超时）
func IncreasingTriplet(nums []int) bool {
	if len(nums) < 3 || nums == nil {
		return false
	}

	ans := make([]int, len(nums))

	for i := range ans {
		ans[i] = 1
	}

	for i := 1; i < len(nums); i++ {
		for j := 0; j < i; j++ {
			if nums[i] > nums[j] {
				ans[i] = max(ans[j]+1, ans[i])
			}
		}
	}

	return max(ans...) >= 3
}

func IncreasingTriplet2(nums []int) bool {

	small, mid := max(nums...), max(nums...)
	fmt.Println(small)

	for _, v := range nums {

		if v <= small {
			small = v
			fmt.Println("change small ", v, "small:", small, "mid:", mid)
		} else if v <= mid {
			mid = v
			fmt.Println("change mid ", v, "small:", small, "mid:", mid)
		} else {
			fmt.Println("return true ", v, "small:", small, "mid:", mid)
			return true
		}
	}

	return false

}
